<?php
declare (strict_types=1);

namespace app\common\model;

use think\Model;

/**
 * @mixin \think\Model
 */
class Adv extends Model
{

    public function getList($param)
    {
        try {
            $map['is_del'] = 0;
            $that = $this->where($map);
            if (isset($param['keyword']) && $param['keyword']) {
                $that->whereLike('code|nickname|mobile', '%' . $param['keyword'] . '%');
            }
            if (isset($param['times']) && $param['times']) {
                $times = explode(' - ', $param['times']);
                $that->whereBetweenTime('create_time', $times[0], $times[1]);
            }

            return $that->paginate(cache('system')['list_rows'], false);
        } catch (\Exception $e) {

            return [];
        }
    }

    public function add($param){
        try {

            if ($param['id']) {

                parent::update($param);

            } else {

                $this->save($param);
            }
            return json(['code' => 1, 'msg' => '操作成功']);

        } catch (\Exception $e) {
            return json(['code' => -1, 'msg' => $e->getMessage()]);
        }
    }

}
